

#include	"SysConfig.h"
#include	"Define.h"
#include	"Port.h"
#include	"Function.h"
#include	"Display.h"
#ifdef  LC786XXX
#include	"LC786XXX.h"
#endif

#ifdef  MIC
#include	"MIC.h"
#endif
#ifdef  CD
#include	"CD.h"
#include	"CD_MECHA.h"

unsigned char ucCD_PortDummy;
#define	P_CD_DECK_SW1	ucCD_PortDummy
#define	P_CD_DECK_SW2	ucCD_PortDummy
#define	P_CD_MOTOR		ucCD_PortDummy
#define	P_CD_PICKUP_SW	ucCD_PortDummy

UI_PLAY_INFO  sCD_PlayInfo;
unsigned char ucCD_Resume;
CD_DISC_TYPE  ucCD_CurrentPlayDiscType;
UI_REPEAT_MODE	ucCD_Repeat;
UI_RANDOM_MODE	ucCD_Random;
UI_SCAN_MODE	ucCD_Scan;
unsigned short usCD_ScanFileNumber;
unsigned char ucCD_FastPlay;

unsigned char ucCD_Pause;
UI_INFO_MODE	ucCD_Display_Info;
UI_ID3TAG_MODE	ucCD_Display_ID3Tag;
UI_CD_TEXT_MODE ucCD_Display_CD_Text;		
unsigned char ucCD_FileName[MEDIA_CHAR_SIZE];
unsigned char ucCD_FileName_CharCode;
unsigned char ucCD_FolderName[MEDIA_CHAR_SIZE];
unsigned char ucCD_FolderName_CharCode;
unsigned char ucCD_ID3_Title[MEDIA_CHAR_SIZE];
unsigned char ucCD_ID3_Title_CharCode;
unsigned char ucCD_ID3_Artist[MEDIA_CHAR_SIZE];
unsigned char ucCD_ID3_Artist_CharCode;
unsigned char ucCD_ID3_Album[MEDIA_CHAR_SIZE];
unsigned char ucCD_ID3_Album_CharCode;
unsigned char ucCD_ID3_AlbumArtist[MEDIA_CHAR_SIZE];
unsigned char ucCD_ID3_AlbumArtist_CharCode;
unsigned char ucCD_TextStatus;
unsigned char ucCD_ErrorCode;

CD_STATUS ucCD_Status;

extern void RANDOM_SetRandom(unsigned short usTotalFile, unsigned short usFirstFile);

extern void AUDIO_BeepOutStart(void);
extern void AUDIO_SetMute(unsigned char ucDes);

#ifdef  FILE_SEARCH
unsigned char	ucCD_FileSearchName[MEDIA_CHAR_SIZE];
unsigned char	ucCD_FileSearchName_CharCode;
extern void LC786XXX_GetFileNameStart(unsigned short ucNum);
extern void LC786XXX_FileSearchPlay(void);
extern void LC786XXX_FileSearch_CopyFileNameCD(void);
#endif

#ifdef  LC78696X
extern LC786X_MEDIA_ID  ucLC786XXX_CurrentMediaID;
extern LC786X_DISC_TYPE ucLC78696X_DiscType;

extern unsigned char ucLC786XXX_RandomFolderSkip;

extern unsigned short	usLC786XXX_CDROM_TotalFolder;

extern unsigned short usLC786XXX_CDROM_TotalFile;
extern unsigned short usLC786XXX_CDDA_FirstTrackNumber;
extern unsigned short usLC786XXX_CDDA_LastTrackNumber;
extern unsigned short usLC786XXX_CDROM_TotalFileInFolder;
extern unsigned short usLC786XXX_CDROM_FirstFileNumberInFolder;
extern void LC786XXX_MoveToStartOfTrack(void);
extern unsigned char LC786XXX_PreviousCondition(void);

extern unsigned char LC786XXX_SkipFile(unsigned char ucDir);
extern void LC786XXX_SkipFolder(unsigned char ucDir);
extern void LC786XXX_FastPlayback(unsigned char ucDir);
extern void LC786XXX_ScanFileChange(void);
extern void DRV_LC786XXX_SetPlayOrder(unsigned char ucMode);
extern unsigned char DRV_LC786XXX_GetPlayOrder(void);
extern unsigned char LC786XXX_CurrentSoundOut(UI_FUNCTION ucFunc);

extern unsigned char DRV_LC786XXX_Playback(LC786X_MEDIA_ID	ucMediaID, unsigned char ucMode);
extern unsigned char DRV_LC786XXX_Set_Repeat(unsigned char ucMode);
extern unsigned char DRV_LC786XXX_PlayOrder(void);
extern unsigned char DRV_LC78696X_PlayCDTrack_AbsoluteTime(UI_PLAY_INFO sPlayInfo);
extern unsigned char DRV_LC786XXX_PlayFileNumber(LC786X_MEDIA_ID ucMediaID, UI_PLAY_INFO sPlayInfo);
extern LC786X_FORMAT	ucLC786X_FileFormat_CD;
extern unsigned char DRV_LC786XXX_GetTotalMediaFile(unsigned char ucMediaID, unsigned char ucMode, unsigned short usFolderNumber);

#endif

extern unsigned short RANDOM_GetNextPlayFileNo(void);
extern unsigned char ucDECK_Disc;

extern unsigned char ucDISP_FolderName;
extern unsigned char ucDISP_FileName;
extern UI_FUNCTION ucFUNC_Current;

void CD_SetTextStatus(unsigned char ucDes)
{
	ucCD_TextStatus = ucCD_TextStatus | ucDes;
}

void CD_ClearTextStatus(unsigned char ucDes)
{
	ucCD_TextStatus = ucCD_TextStatus & (~ucDes);
}

unsigned char CD_GetTextStatus(unsigned char ucDes)
{
	if  ((ucCD_TextStatus & ucDes) == ucDes)
	{
		return(1);
	}
	return(0);
}

unsigned char CD_ClearFastPlayFlag(void)
{
	ucCD_FastPlay = MEDIA_NORMAL_PLAY;
}

unsigned char CD_SoundStatus(void)
{
	if  (FUNC_GetCurrentFunction() == FUNC_CD)
	{
		return(LC786XXX_CurrentSoundOut(FUNC_CD));
	}
	return(1);
}

unsigned char CD_RandomFileChange(unsigned char ucMode)
{
	unsigned short usNextFileNo;
	UI_PLAY_INFO sPlayInfo;
	
	if	(ucCD_FastPlay == MEDIA_FAST_BACKWARD_PLAY)
	{
		CD_FFREW_Release();
		return(0);
	}

	if  (ucMode == 0)
	{
		if  (LC786XXX_PreviousCondition() == 1)
		{
			LC786XXX_MoveToStartOfTrack();
			AUDIO_SetMute(0);
			return(0);
		}
	}
	
	usNextFileNo = RANDOM_GetNextPlayFileNo();
//	CD_ClearTextStatus(0xFF);

//	if  (usNextFileNo != sCD_PlayInfo.FileNo)
//	{
//		CD_ClearTextStatus(0xFF);
//	}
	DISP_PageScrollReset();
#ifdef  LC78696X
	sPlayInfo.FileNo = usNextFileNo;
	sPlayInfo.FolderNo = 0;
	sPlayInfo.Hour = 0;
	sPlayInfo.Min = 0;
	sPlayInfo.Sec = 0;
//	ucDISP_FolderName = 0;
//	ucDISP_FileName = 1;
	if  (ucLC786XXX_CurrentMediaID == LC786X_CDROM)
	{
		DRV_LC786XXX_PlayFileNumber(LC786X_CDROM, sPlayInfo);
	}
	
	if  (ucLC786XXX_CurrentMediaID == LC786X_CDDA)
	{
		unsigned char ucTime[3];

		memset(&ucTime[0], 0x00, 3);
		DRV_LC78696X_PlayCDTrack_AbsoluteTime(sPlayInfo);
	}
#endif
	if  (ucCD_FastPlay == MEDIA_FAST_FORWARD_PLAY)
	{
		CD_FastForwardStart();
	}
	return(1);
}

#ifdef  FILE_SEARCH

void CD_FileSearchPlay(void)
{
	CD_ClearTextStatus(0xFF);
	CD_SetTextStatus(UI_TEXT_READY_FILENAME);
	LC786XXX_FileSearchPlay();
	LC786XXX_FileSearch_CopyFileNameCD();
	ucDISP_FolderName = 0;
	ucDISP_FileName = 0;
}
/*//////////////////////////////////////////////////////////////////
	Title : void USB_FileSearch(unsigned char ucDes)
	ucDir :Direction
		-. 0 : down
		-. 1 : Up
	ucMode :
		-. 0 : Reset Search File Number
		-. 1 : Change Search File Number
//////////////////////////////////////////////////////////////////*/

unsigned short usCD_FileSearchNumber;
unsigned char CD_FileSearch(unsigned char ucMode, unsigned char ucDir)
{
	unsigned short usTotalFile;
	unsigned char ucFirstNum;
	
	if  (ucCD_CurrentPlayDiscType == CD_DISC_CDDA)
	{
		usTotalFile = usLC786XXX_CDDA_LastTrackNumber;
		ucFirstNum = usLC786XXX_CDDA_FirstTrackNumber;
	}
	else
	{
		usTotalFile = usLC786XXX_CDROM_TotalFile;
		ucFirstNum = 1;
	}
	if  (ucMode == 0)
	{
		usCD_FileSearchNumber = sCD_PlayInfo.FileNo;
	}

	if  (ucDir == 0)
	{
		if  (usCD_FileSearchNumber > ucFirstNum)
		{
			--usCD_FileSearchNumber;
		}
		else
		{
			usCD_FileSearchNumber = usTotalFile;
		}
	}
	else
	{
		if  (++usCD_FileSearchNumber > usTotalFile)
		{
			usCD_FileSearchNumber = ucFirstNum;
		}
	}
	
	LC786XXX_GetFileNameStart(usCD_FileSearchNumber);
	ucDISP_FolderName = 0;
}
#endif

/*//////////////////////////////////////////////////////////////////
	Title : void UI_CD_FileChange(unsigned char ucDes)
	ucDes
		-. 0 : down
		-. 1 : Up
//////////////////////////////////////////////////////////////////*/
unsigned char CD_FileChange(unsigned char ucDes)
{
	unsigned char ucRet = 1;
	
	CD_PauseOff(0);
	CD_ScanOff();

	if  ((ucCD_Random == RANDOM_ALL) || (ucCD_Random == RANDOM_FOLDER))
	{
		ucRet = CD_RandomFileChange(ucDes);
		return(ucRet);
	}
#ifdef  LC786XXX
	if  (LC786XXX_SkipFile(ucDes) == 0)
	{
		AUDIO_SetMute(0);
		DISP_PageScrollReset();
		ucRet = 0;
	}
	else
	{
	//	CD_ClearTextStatus(0xFF);
	//	DISP_PageScrollReset();
	//	if  (ucLC786XXX_CurrentMediaID == LC786X_CDROM)
	//	{
	//		ucDISP_FileName = 1;
	//	}
	//	ucDISP_FolderName = 0;
		ucRet = 1;
	}
#endif
	return(ucRet);
}

void CD_RandomOff(void)
{
	if  (ucCD_Random == RANDOM_NONE)
	{
		return;
	}
	ucCD_Random = RANDOM_NONE;
#ifdef  LC78696X
	DRV_LC786XXX_SetPlayOrder(DRV_LC786XXX_GetPlayOrder() & 0xFC);
	DRV_LC786XXX_PlayOrder();
#endif
}

/*//////////////////////////////////////////////////////////////////
	Title : void UI_CD_FileChange(unsigned char ucDes)
	ucDes
		-. 0 : down
		-. 1 : Up
//////////////////////////////////////////////////////////////////*/

unsigned char CD_FolderChange(unsigned char ucDes)
{
#ifdef  LC78696X
	if  (ucLC78696X_DiscType == LC786X_DISC_CDDA)
	{
		return(0);
	}
#endif
	CD_PauseOff(0);
	CD_ScanOff();
	
	if  (ucCD_Random == RANDOM_NONE)
	{
		#ifdef  LC786XXX
		LC786XXX_SkipFolder(ucDes);
		#endif
	}
	else
	{
		unsigned short usFolderNumber;
		
		ucLC786XXX_RandomFolderSkip = ucCD_Random;
		usFolderNumber = sCD_PlayInfo.FolderNo;

		if  (ucDes == 0)	// Down
		{
			if  (usFolderNumber == 1)
			{
				usFolderNumber = usLC786XXX_CDROM_TotalFolder;
			}
			else
			{
				--usFolderNumber;
			}
		}
		else
		{
			++usFolderNumber;

			if  (usFolderNumber > usLC786XXX_CDROM_TotalFolder)
			{
				usFolderNumber = 1;
			}
		}
		DRV_LC786XXX_GetTotalMediaFile(LC786X_CDROM,0x01,usFolderNumber);
	}

	return(1);
}

void CD_ScanOff(void)
{
	if  (ucCD_Scan == SCAN_NONE)
	{
		return;
	}

#ifdef	LC78696X
	if  (ucCD_Scan == SCAN_FOLDER)
	{
		DRV_LC786XXX_Set_Repeat(LC786X_RPT_ALL);
	}
#endif
	ucCD_Scan = SCAN_NONE;
}

void CD_RepeatOff(void)
{
	if  (ucCD_Repeat == REPEAT_NONE)
	{
		return;
	}

	ucCD_Repeat = REPEAT_NONE;
#ifdef  LC78696X
	DRV_LC786XXX_Set_Repeat(LC786X_RPT_ALL);
#endif
}

/*///////////////////////////////////////////////////////////////
Title : void CD_PauseOff(unsigned char ucDes)
ucDes
  0 : Clear Flag Only
  1 : Clear Flag and Send command for play
////////////////////////////////////////////////////////////////*/

void CD_PauseOff(unsigned char ucDes)
{
	if  (ucCD_Pause == 0)
	{
		return;
	}
	if  (ucDes == 1)
	{
		#ifdef  LC78696X
		if  (LC786XXX_GetMediaStatus(FUNC_CD) == LC786X_MS_PAUSE)
		{
			if  (ucCD_CurrentPlayDiscType == CD_DISC_CDDA)
			{
				DRV_LC786XXX_Playback(LC786X_CDDA, 0x01);
			}
			else
			{
				DRV_LC786XXX_Playback(LC786X_CDROM, 0x01);
			}
			ucCD_Pause = 0;
		}
		#endif
	}
	else
	{
		ucCD_Pause = 0;
	}
}

void CD_SetRepeat(void)
{
	CD_PauseOff(1);
	CD_ScanOff();
	CD_RandomOff();
	
#ifdef  LC78696X
	if  (ucCD_CurrentPlayDiscType == CD_DISC_CDROM)
	{
		if  (++ucCD_Repeat > REPEAT_FOLDER)
		{
			CD_RepeatOff();
		}
	}
	else
	{
		if  (ucCD_Repeat == REPEAT_FILE)
		{
			CD_RepeatOff();
		}
		else
		{
			ucCD_Repeat = REPEAT_FILE;
		}
	}
	switch  (ucCD_Repeat)
	{
		case REPEAT_NONE:
			DRV_LC786XXX_Set_Repeat(LC786X_RPT_ALL);
			break;
		case REPEAT_FILE:
			DRV_LC786XXX_Set_Repeat(LC786X_RPT_FILE);
			break;
		case REPEAT_FOLDER:
			DRV_LC786XXX_Set_Repeat(LC786X_RPT_FLD);
			break;
	}
#endif
}

unsigned char CD_SetPausePlay(void)
{
	if  (ucCD_Pause == 0)
	{		
	#ifdef  LC78696X
		if  (LC786XXX_GetMediaStatus(FUNC_CD) == LC786X_MS_PLAYBACK)
		{
			ucCD_Pause = 1;
			if  (ucCD_CurrentPlayDiscType == CD_DISC_CDROM)
			{
				DRV_LC786XXX_Playback(LC786X_CDROM, 0x02);	// Pause
			}
			else
			{
				DRV_LC786XXX_Playback(LC786X_CDDA, 0x02);	// Pause
			}
		}
	#endif
	}
	else
	{
	#ifdef  LC78696X
		if  (LC786XXX_GetMediaStatus(FUNC_CD) == LC786X_MS_PAUSE)
		{
			ucCD_Pause = 0;
			if  (ucCD_CurrentPlayDiscType == CD_DISC_CDROM)
			{
				DRV_LC786XXX_Playback(LC786X_CDROM, 0x01);	// Pause
			}
			else
			{
				DRV_LC786XXX_Playback(LC786X_CDDA, 0x01);	// Pause
			}
		}
	#endif
	}

	return(ucCD_Pause);
}

void CD_CDROM_SetRandom(void)
{
	if  (++ucCD_Random > RANDOM_FOLDER)
	{
		CD_RandomOff();
	}

	switch  (ucCD_Random)
	{
		case RANDOM_ALL:
			RANDOM_SetRandom(usLC786XXX_CDROM_TotalFile, 1);
			CD_RandomFileChange(1);
			break;
		case RANDOM_FOLDER:
			RANDOM_SetRandom(usLC786XXX_CDROM_TotalFileInFolder, usLC786XXX_CDROM_FirstFileNumberInFolder);
			CD_RandomFileChange(1);
			break;
	}
}

void CD_CDDA_SetRandom(void)
{
	if  (ucCD_Random == RANDOM_ALL)
	{
		CD_RandomOff();
	}
	else
	{
		ucCD_Random = RANDOM_ALL; 
		RANDOM_SetRandom(usLC786XXX_CDDA_LastTrackNumber - usLC786XXX_CDDA_FirstTrackNumber + 1,usLC786XXX_CDDA_FirstTrackNumber);
		CD_RandomFileChange(1);
	}
}

void CD_SetRandom(void)
{
	CD_PauseOff(1);
	CD_RepeatOff();
	CD_ScanOff();

	DRV_LC786XXX_SetPlayOrder(DRV_LC786XXX_GetPlayOrder() | 0x03);
	DRV_LC786XXX_PlayOrder();

	if  (ucLC78696X_DiscType == LC786X_DISC_CDDA)
	{
		CD_CDDA_SetRandom();
	}
	else  if  (ucLC78696X_DiscType == LC786X_DISC_CDROM)
	{
		CD_CDROM_SetRandom();
	}
	else  if  (ucLC78696X_DiscType == LC786X_DISC_MIXED)
	{
		if  (ucCD_CurrentPlayDiscType == CD_DISC_CDDA)
		{
			CD_CDDA_SetRandom();
		}
		else  if  (ucCD_CurrentPlayDiscType == CD_DISC_CDROM)
		{
			CD_CDROM_SetRandom();
		}
	}
}

void CD_SetScan(void)
{
	CD_PauseOff(1);
	CD_RepeatOff();
	CD_RandomOff();

#ifdef  LC78696X
	if  (ucCD_CurrentPlayDiscType == CD_DISC_CDROM)
	{
		if  (++ucCD_Scan > SCAN_FOLDER)
		{
			CD_ScanOff();
		}
	}
	else
	{
		if  (ucCD_Scan == SCAN_ALL)
		{
			CD_ScanOff();
		}
		else
		{
			ucCD_Scan = SCAN_ALL;
		}
	}
	
	switch  (ucCD_Scan)
	{
		case SCAN_NONE:
			//usCD_ScanFileNumber = sCD_PlayInfo.FileNo;
			DRV_LC786XXX_Set_Repeat(LC786X_RPT_ALL);	// Set to Disc Repeat
			break;
		case SCAN_FOLDER:
			DRV_LC786XXX_Set_Repeat(LC786X_RPT_FLD);	// Set to Folder repeat
			usCD_ScanFileNumber = sCD_PlayInfo.FileNo;
			break;
		case SCAN_ALL:
			LC786XXX_ScanFileChange();
	//		CD_ClearTextStatus(0xFF);
			usCD_ScanFileNumber = sCD_PlayInfo.FileNo;
			DRV_LC786XXX_Set_Repeat(LC786X_RPT_ALL);	// Set to Disc Repeat
			break;
	}
#endif	
}

unsigned char CD_GetFastPlayStatus(void)
{
	return(ucCD_FastPlay);
}

void CD_FastForwardStart(void)
{
	CD_PauseOff(1);
	CD_ScanOff();
	#ifdef  LC786XXX
	if  (ucCD_Repeat == REPEAT_FILE)
	{
		DRV_LC786XXX_SetPlayOrder(0x40 | 0x3F);
	}
	if  (ucCD_Repeat == REPEAT_FOLDER)
	{
		DRV_LC786XXX_SetPlayOrder(0x40 | 0x3E);
	}
	if  ((ucCD_Random == RANDOM_FOLDER) || (ucCD_Random == RANDOM_ALL))
	{
		DRV_LC786XXX_SetPlayOrder(0x40);
	}
	if  ((ucCD_Random == RANDOM_NONE) && (ucCD_Repeat == REPEAT_NONE))
	{
		DRV_LC786XXX_SetPlayOrder(0x40);
	}
	LC786XXX_FastPlayback(0x00);
	#endif

	ucCD_FastPlay = MEDIA_FAST_FORWARD_PLAY;
}

void CD_FastBackwardStart(void)
{
	CD_PauseOff(1);
	CD_ScanOff();
	#ifdef  LC786XXX
	if  (ucCD_Repeat == REPEAT_FILE)
	{
		DRV_LC786XXX_SetPlayOrder(0x40 | 0x3F);
	}
	if  (ucCD_Repeat == REPEAT_FOLDER)
	{
		DRV_LC786XXX_SetPlayOrder(0x40 | 0x3D);
	}
	if  ((ucCD_Random == RANDOM_FOLDER) || (ucCD_Random == RANDOM_ALL))
	{
		DRV_LC786XXX_SetPlayOrder(0x40 | 0x20);
	}

	if  ((ucCD_Random == RANDOM_NONE) && (ucCD_Repeat == REPEAT_NONE))
	{
		DRV_LC786XXX_SetPlayOrder(0x40 | 0x20);
	}
	
	LC786XXX_FastPlayback(0x01);
	#endif
	ucCD_FastPlay = MEDIA_FAST_BACKWARD_PLAY;
}

void CD_FFREW_Release(void)
{
	#ifdef  LC786XXX
	if  ((ucCD_Repeat == REPEAT_FOLDER) || (ucCD_Repeat == REPEAT_FILE))
	{
		DRV_LC786XXX_SetPlayOrder(0x40);
	}
	if  ((ucCD_Random == RANDOM_FOLDER) || (ucCD_Random == RANDOM_ALL))
	{
		DRV_LC786XXX_SetPlayOrder(0x43);
	}
	if  ((ucCD_Random == RANDOM_NONE) && (ucCD_Repeat == REPEAT_NONE))
	{
		DRV_LC786XXX_SetPlayOrder(0x40);
	}
	LC786XXX_FastPlayback(0x03);
	#endif
	ucCD_FastPlay = MEDIA_NORMAL_PLAY;
	DISP_PageScrollReset();
}

/*//////////////////////////////////////////////////////////////////
	Title : void UI_CD_Info(unsigned short ucMode)
	0 : Short Key, Current Display Infomation change
	1 : Long Key, Tag Mode change
*/////////////////////////////////////////////////////////////////////////////
void CD_SetInfo(unsigned short ucMode)
{
	CD_PauseOff(1);
	DISP_PageScrollReset();
	ucDISP_FolderName = 0;
	ucDISP_FileName = 0;
#ifdef  LC78696X
	if  (ucMode == 1)
	{
		if  (ucCD_CurrentPlayDiscType == CD_DISC_CDDA)
		{
			if  (ucCD_TextStatus == 0)
			{
				DISP_SetTempDisplayMode_3Sec(DISP_NO_INFO);
				return;
			}
			if  (ucCD_Display_Info == INFO_FILENAME)
			{
				if  (++ucCD_Display_CD_Text > CD_TEXT_ARTIST)
				{
					ucCD_Display_CD_Text = CD_TEXT_ALBUM;
				}
			}
			else
			{
				ucCD_Display_Info = INFO_FILENAME;
			}
		
		}
		else
		{
			if  (ucCD_Display_Info == INFO_ID3TAG)
			{
				if  (++ucCD_Display_ID3Tag > ID3TAG_BITRATE)
				{
					ucCD_Display_ID3Tag = ID3TAG_TITLE;
				}
			}
			else
			{
				ucCD_Display_Info = INFO_ID3TAG;
			}
		}
		return;
	}
		
	if  (ucCD_CurrentPlayDiscType == LC786X_DISC_CDROM)
	{
		if  (++ucCD_Display_Info > INFO_ID3TAG)
		{
			ucCD_Display_Info = INFO_FILENAME;
		}
	}
	else
	{	
		if  (ucCD_Display_Info == INFO_FILENAME)
		{
			ucCD_Display_Info = INFO_PLAYTIME;
		}
		else
		{
			ucCD_Display_Info = INFO_FILENAME;
		}
		return;
	}
#endif

}

/*//////////////////////////////////////////////////////////////////
Title : void UI_CD_Eject(unsigned char ucDes)
0 : Normal Eject
1 : Force Eject
*/////////////////////////////////////////////////////////////////////////////
void CD_SetEject(unsigned char ucDes)
{
	if  (DECK_CurrentMode_Eject() == 1)
	{
		return;
	}
	
#if  1
	if  (ucDes == 1)
	{
		if  (DECK_CurrentMode_Remove() == 1)
		{
			return;
		}
		MENU_Clear();
		if  (ucDECK_Disc == 1)
		{
			FUNC_FunctionChangeStart(FUNC_GetPreviousFunction(), FUNC_CHANGE_SEQ0);
			DECK_SetMode(DECK_MODE_EJECT);
			LC786XXX_SetEjectProcess();
			if (FUNC_GetCurrentFunction() == FUNC_CD)
			{
				DISP_SetTempDisplayMode(DISP_EJECT);
			#ifdef  MIC
				if  (MIC_GetHostMicStatus() == MIC_ON)
				{
					MIC_SetHostMicStatus(MIC_OFF);
				}
			#endif
			}
		}
		else
		{
			AUDIO_BeepOutStart();
			DECK_SetMode(DECK_MODE_EJECT);
		}
	}
	else
	{
		if  (ucDECK_Disc == 0)
		{
			return;
		}
		
		MENU_Clear();		
		if  (FUNC_PowerStatus())
		{
			DISP_SetTempDisplayMode(DISP_EJECT);
		}
		DECK_SetMode(DECK_MODE_EJECT);
		LC786XXX_SetEjectProcess();

		if  (FUNC_GetCurrentFunction() == FUNC_CD)
		{
			if  (FUNC_PowerStatus())
			{
				FUNC_FunctionChangeStart(FUNC_GetPreviousFunction(), FUNC_CHANGE_SEQ0);
			#ifdef  MIC
				if  (MIC_GetHostMicStatus() == MIC_ON)
				{
					MIC_SetHostMicStatus(MIC_OFF);
				}
			#endif
			}
			else
			{
				ucFUNC_Current = FUNC_GetPreviousFunction();
			}
		}
	}
#else
	if  ((FUNC_GetCurrentFunction() == FUNC_CD) && (FUNC_PowerStatus() == 1) && (ucDECK_Disc == 1))
	{
		MENU_Clear();
		FUNC_FunctionChangeStart(FUNC_GetPreviousFunction(), FUNC_CHANGE_SEQ0);
		DISP_SetTempDisplayMode(DISP_EJECT);
		DECK_SetMode(DECK_MODE_EJECT);
		return;
	}
	
	if  ((FUNC_GetCurrentFunction() == FUNC_CD) && (ucDECK_Disc == 1))
	{
		ucFUNC_Current = FUNC_GetPreviousFunction();
	}

	if  (ucDes == 1)
	{
		if  (DECK_CurrentMode_Remove() == 1)
		{
			return;
		}
		MENU_Clear();
		if  (ucDECK_Disc == 1)
		{
			DECK_SetMode(DECK_MODE_EJECT);
			LC786XXX_SetEjectProcess();
			if (FUNC_GetCurrentFunction() == FUNC_CD)
			{
				DISP_SetTempDisplayMode(DISP_EJECT);
			}
		}
		else
		{
			AUDIO_BeepOutStart();
			DECK_SetMode(DECK_MODE_EJECT);
		}
	}
	else
	{
		if  (ucDECK_Disc == 1)
		{
			MENU_Clear();
			DECK_SetMode(DECK_MODE_EJECT);
			LC786XXX_SetEjectProcess();
		}
	}
#endif
}

void CD_Variable_Initalize(void)
{
	sCD_PlayInfo.FolderNo = 0;
	sCD_PlayInfo.FileNo = 0;
	sCD_PlayInfo.Hour = 0;
	sCD_PlayInfo.Min = 0;
	sCD_PlayInfo.Sec = 0;
	sCD_PlayInfo.BitRate = 0;
	ucCD_Resume = 0;
	ucCD_Repeat = REPEAT_NONE;
	ucCD_Random = RANDOM_NONE;
	ucCD_Pause = 0;
	ucCD_Display_Info = INFO_FILENAME;
	ucCD_Display_ID3Tag = ID3TAG_TITLE;
	ucCD_Display_CD_Text = CD_TEXT_ALBUM;
	ucCD_TextStatus = 0;
	ucCD_Scan = SCAN_NONE;
	usCD_ScanFileNumber = 0;
	memset(&ucCD_FileName[0], 0x00, MEDIA_CHAR_SIZE);
	memset(&ucCD_FolderName[0], 0x00, MEDIA_CHAR_SIZE);
	memset(&ucCD_ID3_Title[0], 0x00, MEDIA_CHAR_SIZE);
	memset(&ucCD_ID3_Artist[0], 0x00, MEDIA_CHAR_SIZE);
	memset(&ucCD_ID3_Album[0], 0x00, MEDIA_CHAR_SIZE);
	ucCD_FastPlay = MEDIA_NORMAL_PLAY;
	ucLC786X_FileFormat_CD = LC786X_FORMAT_UNKNOWN;
	ucCD_CurrentPlayDiscType = CD_DISC_CDDA;
	ucCD_ErrorCode = LC786X_EC_NoError;	
}

#endif



